<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>仓库管理</title>

		<link rel="stylesheet" href="../css/index.css">

		<script src="../js/vue.min.js"></script>
		<script src="../js/elementui.js"></script>
		<script src="../js/axios.min.js"></script>
		<script src="../js/mycommon.js"></script>

		<style>
			.page {
			    position: fixed;
			    bottom: 0;
			    height: 35%;
			    width: 90%;
			    text-align: center;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<fieldset style="border: 1px solid gainsboro;margin-bottom: 4px;">
				<legend><i class="el-icon-search" style="color:#bfb6a3 ;">查询</i></legend>
				<el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
					<el-form-item label="输入仓库名">
						<el-input v-model="formInline.warehouse" placeholder="输入仓库名"></el-input>
					</el-form-item>

					<el-form-item>
						<el-button type="primary" @click="onSubmitC">查询</el-button>
						<el-button type="warning" @click="open">增加仓库</el-button>
					</el-form-item>
				</el-form>
			</fieldset>

			<el-table :data="warehouseData" border style="width: 100% "  :cell-style="{'text-align':'center'}"
				:header-cell-style="{'text-align':'center'}">
				<el-table-column prop="warehouse" label="仓库名" width="280">
				</el-table-column>
				<el-table-column prop="remarks" label="备注" width="580">
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" @click="handleEdit(scope.$index, scope.row)" type="primary">编辑</el-button>

					</template>
				</el-table-column>
			</el-table>

			<!-- 分页 -->
			<div class="page">
				<el-pagination @current-change="handleCurrentChange" background layout="prev, pager, next"
					:total="tocal" :page-size="pagesize">
				</el-pagination>
			</div>


			<!--增加仓库开始-->
			<el-dialog title="增加角色" :visible.sync="dialogVisible" width="50%">

				<el-form ref="form" :model="sizeForm" label-width="100px" size="mini">
					<el-form-item label="仓库名字">
						<el-input v-model="sizeForm.warehouse"></el-input>
					</el-form-item>

					<el-form-item label="备注">
						<el-input v-model="sizeForm.remarks"></el-input>
					</el-form-item>
				</el-form>

				<span slot="footer" class="dialog-footer">
					<el-button size="mini" @click="dialogVisible = false" type="danger">取 消</el-button>
					<el-button size="mini" type="primary" @click="onSubmit" type="primary">确 定</el-button>
				</span>
			</el-dialog>
			<!--增加仓库结束-->

			<!-- 修改仓库开始 -->
			<el-dialog title="修改仓库" :visible.sync="dialogVisible1" width="50%">

				<el-form ref="form1" :model="sizeForm1" label-width="100px" size="mini">
					<el-form-item label="仓库名字" prop="warehouse">
						<el-input v-model="sizeForm1.warehouse"></el-input>
					</el-form-item>

					<el-form-item label="备注" prop="remarks">
						<el-input v-model="sizeForm1.remarks"></el-input>
					</el-form-item>
				</el-form>

				<span slot="footer" class="dialog-footer">
					<el-button size="mini" @click="dialogVisible1 = false" type="danger">取 消</el-button>
					<el-button size="mini" type="primary" @click="onSubmit1" type="primary">确 定</el-button>
				</span>
			</el-dialog>
			<!-- 修改仓库结束 -->


		</div>

		<script>
			var vm = new Vue({
				el: "#app",
				data: {
					warehouseData: [],
					formInline: {
						warehouse: ''
					},
					page: 1, //当前第几页
					tocal: 0, //总条数
					pagesize: 5, //每页条数

					dialogVisible: false,
					dialogVisible1: false,
					sizeForm: {
						warehouse: '',
						remarks: ''
					},
					sizeForm1: {
						warehouse: '',
						remarks: ''
					}
				},
				methods: {


					onSubmit() { //增加仓库

						//执行业务提交
						this.dialogVisible = false
						var that = this
						// alert(JSON.stringify(this.sizeForm))
						axios.post(HTTP + "warehouse/addware", this.sizeForm).then(function(res) {
							if (res.data.code == 200) {
								that.$message('增加角色成功')
								that.initdata()
							}
						}).catch(err => {
							console.log(err)
						});

					},

					onSubmit1() { //提交修改数据
						this.$confirm('确定修改该仓库信息?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning',
							center: true
						}).then(() => {
							this.dialogVisible1 = false
							var that = this
							axios.post(HTTP + "warehouse/upware", this.sizeForm1).then(function(res) {
								if (res.data.code == 200) {
									that.$message('修改成功')
									that.initdata()
								}
							}).catch(err => {
								console.log(err)
							});
						})
					},

					handleCurrentChange(val) { //分页
						this.page = val //设置当前页
						this.initdata() //发送ajax请求重新获取数据
					},

					handleEdit(index, row) { //查询需要修改的数据
						console.log(index, row.id);
						this.dialogVisible1 = true
						var that = this
						axios.post(HTTP + "warehouse/seloneid", {
							"id": row.id
						}).then(function(res) {
							// alert(JSON.stringify(res));
							that.sizeForm1 = res.data.data.oneid
						}).catch(err => {
							console.log(err)
						});
					},
					onSubmitC() { //按条件查询

						var that = this
						//alert(JSON.stringify(this.formInline))
						axios.post(HTTP + "warehouse/select", this.formInline).then(function(res) {
							//alert(JSON.stringify(res));
							that.warehouseData = res.data.data.list
							that.tocal = res.data.data.total

						}).catch(err => {
							console.log(err)
						});
					},
					open() {
						this.dialogVisible = true
					},

					initdata() { //初始化
						var that = this
						//ajax请求后端接口获取json数据
						axios.post(HTTP + "warehouse/pageselect/" + this.page).then(function(res) {
							// alert(JSON.stringify(res));
							that.warehouseData = res.data.data.pageInfo.list
							that.tocal = res.data.data.pageInfo.total

						}).catch(err => {
							console.log(err)
						});
					}
				},
				mounted() { //vue生命周期的方法
					//发送ajax请求到后端接口，获取json数据
					this.initdata()
				}
			})
		</script>
	</body>
</html>